package com.ifood.web.controller.system;

import javax.servlet.http.HttpServletResponse;

import com.ifood.common.core.domain.entity.IFoodProductInfo;
import com.ifood.common.utils.poi.ExcelUtil;
import com.ifood.system.service.IIFoodProductInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ifood.common.annotation.Log;
import com.ifood.common.core.controller.BaseController;
import com.ifood.common.core.domain.AjaxResult;
import com.ifood.common.enums.BusinessType;
import com.ifood.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 商品基本信息Controller
 *
 * @author ifood
 * @date 2024-01-12
 */
@RestController
@Api(tags = "商品基本信息")
@RequestMapping("/system/product")
public class IFoodProductInfoController extends BaseController {
    @Autowired
    private IIFoodProductInfoService iFoodProductInfoService;

    /**
     * 查询商品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @GetMapping("/list")
    @ApiOperation("查询商品基本信息列表")
    public TableDataInfo list(IFoodProductInfo iFoodProductInfo) {
        startPage();
        List<IFoodProductInfo> list = iFoodProductInfoService.selectIFoodProductInfoList(iFoodProductInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "商品基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IFoodProductInfo iFoodProductInfo) {
        List<IFoodProductInfo> list = iFoodProductInfoService.selectIFoodProductInfoList(iFoodProductInfo);
        ExcelUtil<IFoodProductInfo> util = new ExcelUtil<IFoodProductInfo>(IFoodProductInfo.class);
        util.exportExcel(response, list, "商品基本信息数据");
    }

    /**
     * 获取商品基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:query')")
    @GetMapping(value = "/{productId}")
    @ApiOperation("获取商品基本信息详细信息")
    public AjaxResult getInfo(@PathVariable("productId") String productId) {
        return success(iFoodProductInfoService.selectIFoodProductInfoByProductId(productId));
    }

    /**
     * 新增商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "商品基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增商品基本信息")
    public AjaxResult add(@RequestBody IFoodProductInfo iFoodProductInfo) {
        return toAjax(iFoodProductInfoService.insertIFoodProductInfo(iFoodProductInfo));
    }

    /**
     * 修改商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "商品基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改商品基本信息")
    public AjaxResult edit(@RequestBody IFoodProductInfo iFoodProductInfo) {
        return toAjax(iFoodProductInfoService.updateIFoodProductInfo(iFoodProductInfo));
    }

    /**
     * 删除商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "商品基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productIds}")
    @ApiOperation("删除商品基本信息")
    public AjaxResult remove(@PathVariable String[] productIds) {
        return toAjax(iFoodProductInfoService.deleteIFoodProductInfoByProductIds(productIds));
    }
}
